package com.wanmait.demo.controller.workercontroller;

import com.github.pagehelper.PageInfo;
import com.wanmait.demo.pojo.OrderBack;
import com.wanmait.demo.pojo.RepairOrder;
import com.wanmait.demo.service.ConfigService;
import com.wanmait.demo.service.OrderBackService;
import com.wanmait.demo.service.RepairOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class MyServiceController {
    @Resource
    private RepairOrderService repairOrderService;
    @Resource
    private ConfigService configService;
    @Resource
    private OrderBackService orderBackService;
    //闫应鹏
    @RequestMapping("workerMyService")
    public ModelAndView getMyService()
    {
        int workerId=1;

        ModelAndView modelAndView=new ModelAndView();
        List<RepairOrder> repairOrders=repairOrderService.findall(workerId);
        modelAndView.addObject("repairOrders",repairOrders);

        modelAndView.setViewName("worker/underwayOrder");
        return  modelAndView;
    }
    @RequestMapping("completedOrder")
    public ModelAndView getcompletedOrder(Integer pageNum)
    {

        //获取config表中分页显示的条数
        int pageSize=configService.findPage();
        Integer workerId =1;
        ModelAndView modelAndView=new ModelAndView();
        PageInfo<RepairOrder> pageInfo=repairOrderService.findWorker(workerId,pageNum,pageSize);
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("worker/completedOrder");
        return modelAndView;
    }

    @RequestMapping("workerchargeback")
    public ModelAndView gettravelList(Integer workerId,Integer orderId)
    {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("workerId",workerId);
        modelAndView.addObject("orderId",orderId);
        modelAndView.setViewName("worker/chargeback");
        return modelAndView;
    }
    @RequestMapping("chargebackApplyFor")
    @ResponseBody
    public void chargebackApplyFor(Integer orderId,String reason)
    {
        Integer workerId=repairOrderService.findWorker(orderId);
        repairOrderService.chargeback(orderId);
        orderBackService.insert(workerId,orderId,reason);

    }

}
